package com.sls.game.dao.enfu.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.enfu.EnfuGoodsDetailDAO;
import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.enfu.EnfuGoodsDetailInfo;

/**
 * 
 * @description
 * @author Wangxuegang
 * @date 2013-5-3
 */
@Repository("enfuGoodsDetailDAO")
public class EnfuGoodsDetailDAOImpl extends SuperDAO<EnfuGoodsDetailInfo>
		implements EnfuGoodsDetailDAO {

	/**
	 * 根据商品编号、游戏名称、游戏编号，单条记录查询
	 * 
	 * @param productid
	 *            恩付商品编号
	 */
	@Override
	public String queryProductDetailInfo(EnfuGoodsDetailInfo enfuGoodsDetailInfo) {
		String id = null;
		id = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuGoodsDetailMapper.queryProductDetailInfo",
				enfuGoodsDetailInfo);

		return id;
	}

	/**
	 * 记录插入
	 * 
	 * @param enInfo
	 */
	@Override
	public void insertInfo(EnfuGoodsDetailInfo enInfo) {
		this.getSqlSession().insert(
				"mybatis.xml.EnfuGoodsDetailMapper.insertInfo", enInfo);
	}

	/**
	 * 记录更新
	 * 
	 * @param enInfo
	 */
	@Override
	public void updateInfo(EnfuGoodsDetailInfo enInfo) {
		this.getSqlSession().update(
				"mybatis.xml.EnfuGoodsDetailMapper.updateInfo", enInfo);

	}

	/**
	 * 去商品详细表
	 * 
	 * @param definedproductid
	 *            自定义原始商品编号
	 * @return
	 */
	@Override
	public EnfuGoodsDetailInfo queryGoodsDetail(String definedproductid) {
		EnfuGoodsDetailInfo enInfo = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuGoodsDetailMapper.queryGoodsDetail",
				definedproductid);
		return enInfo;
	}

	/**
	 * 商品详细--分页查询
	 * 
	 * @param detailInfo
	 * @return
	 */
	@Override
	public Pagination<EnfuGoodsDetailInfo> queryPaginationList(
			EnfuGoodsDetailInfo detailInfo) {
		Pagination<EnfuGoodsDetailInfo> paginationList = null;
		int rowCount = queryRowCount(detailInfo);
		detailInfo.calculate();
		List<EnfuGoodsDetailInfo> list = queryResultList(detailInfo);
		paginationList = queryPagination(rowCount, list, detailInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param detailInfo
	 * @return
	 */
	private int queryRowCount(EnfuGoodsDetailInfo detailInfo) {
		int rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.EnfuGoodsDetailMapper.queryRowCount", detailInfo);
		return rowCount;
	}

	/**
	 * 查询结果记录集
	 * 
	 * @param detailInfo
	 * @return
	 */
	private List<EnfuGoodsDetailInfo> queryResultList(
			EnfuGoodsDetailInfo detailInfo) {
		List<EnfuGoodsDetailInfo> list = null;
		list = this.getSqlSession()
				.selectList(
						"mybatis.xml.EnfuGoodsDetailMapper.queryResultList",
						detailInfo);
		return list;
	}

	/**
	 * 查询所有自定义原始商品编号
	 * 
	 * @return
	 */
	@Override
	public List<String> queryAllDefinedproductid() {
		List<String> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.EnfuGoodsDetailMapper.queryAllDefinedproductid");
		return list;
	}
}
